<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility"%>
<%@ include file="/public/header.jsp"%>
<%
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String truename=String.valueOf(sessionMap.get("truename"));
%>
<html>
<head>
<title>工单管理</title>
</head>
<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$('#gd_status').combobox({
				 url:'<%=contextPath%>/springMVC/gd/listGDStatus',
				 valueField:'id',
				 textField:'text',
				 onChange:function(){
						doSearch();
					}
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#searchValue2").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch2();
		       	} 
		   	}); 
			jQuery('#gd_admin_id').combogrid({
				title:'派单人选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tba",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch2();
				}
			});
			$("#table").datagrid({
				title:"工单管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath%>/springMVC/gd/listPageGDBase?flagType=1',
				rownumbers:true,
				singleSelect:true,
				fitColumns:true,
				idField:'id',
				nowrap:false,
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'项目id',field:'xm_id',hidden:true},
				    {title:'项目编号',field:'xm_code',hidden:true},
				    {title:'项目名称',field:'xm_name',hidden:true},
				    {title:'客户id',field:'customer_id',hidden:true},
				    {title:'客户',field:'customer',hidden:true},
				    {title:'最新的工单内容id',field:'gd_content_id',hidden:true},
				    {title:'所属部门id',field:'dept_id',hidden:true}
				]],
				columns:[[
					{title:'工单状态',field:'gd_status',hidden:true},
					{title:'工单进度',field:'gd_status_desc',width:80,align:'center'},
					{title:'派单人',field:'gd_admin_name',width:80,align:'center'},
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:100,align:'center'},
					{title:'工单类型',field:'gd_type',width:10,align:'center',hidden:true},
					{title:'班组名称',field:'gd_worker_id',width:10,align:'center',hidden:true},
					{title:'班组名称',field:'gd_worker_name',width:100,align:'center'},
					{title:'班组负责人',field:'gd_worker_person',width:100,align:'center'},
					{title:'完工日期',field:'gd_actual_end',width:100,align:'center'},
					{title:'分包纠错',field:'optZy',width:40,align:'center',formatter:function(value,rowData,rowIndex){
	                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-edit'  onclick=\"javascript:optWorkerBg('"+rowData.gd_worker_id+"','"+rowData.gd_worker_person+"','"+rowData.gd_worker_name+"','"+rowData.id+"');\"/>";
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function optWorkerBg(gd_worker_id,gd_worker_person,gd_worker_name,gd_id){
			$.messager.confirm('确认','您确认要更改分包商名称吗？',function(msg){
			if(msg){
				openDialogResize('<%=contextPath%>/springViews/gd/addOrEditWorker.jsp?callback=rtCallBack&worker_id='+gd_worker_id+'&gd_worker_person='+gd_worker_person+'&gd_worker_name='+gd_worker_name+'&gd_id='+gd_id,800, 800);
				}
			});
			}
		function showGD(gd_id,gd_content_id){
			openDialogResize('<%=contextPath%>/springViews/gd/showGd.jsp?gd_id='+gd_id+'&gd_content_id='+gd_content_id,1000, 800);
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		//添加进程
		function addProcess(gd_id,gd_name,gd_code){
			openDialogResize('<%=contextPath%>/springViews/gd/processManage.jsp?gd_id='+gd_id+'&gd_name='+encodeURIComponent(gd_name)+'&gd_code='+gd_code,1000, 800);

		}
		//安质检查
		function securityCheck(gd_id,gd_name,gd_code){
			openDialogResize('<%=contextPath%>/springViews/gd/securityCheckManage.jsp?gd_id='+gd_id+'&gd_name='+encodeURIComponent(gd_name)+'&gd_code='+gd_code,1000, 800);
		}
		//发起核算
		function startAccounting(status,gd_id,gd_content_id,gd_name,gd_code,xm_name,xm_code){
			var rows=$('#table').datagrid('getSelections');
			$.ajax({
				type:'GET',
				url:'<%=contextPath %>/springMVC/gd/getDbBorrowMaterial?gd_id='+gd_id,
				async:false,
				success:function(rtJson){
					if(rtJson == '1'){
						$.messager.alert("提示","该工单还有未完成的还料！不能发起核算！");
						return false;
					}
					if(rtJson == '2'){
						warningInfo("工单存在没有报账的借款，请先在项目侧报账！");
						return;
					}else if (rtJson == '3'){
						warningInfo("工单存在没有处理的待补采购单，请先处理！");
						return;
					}
			$.ajax({
				type:'POST',
				url:'<%=contextPath %>/springMVC/gd/checkAssumeMaterialControl?gd_id='+gd_id+'&gd_content_id='+gd_content_id,
				async:false,
				success:function(rtJson){
					if(rtJson != 0){
						$.messager.alert("提示","该工单材料使用量低于材料管控最小范围，请调整预算或变更实际使用量！");
						return false;
					}
			if(status >= '<%=com.beaut.project.util.StaticData.ACCOUTING%>'){
				openDialogResize('<%=contextPath%>/springViews/gd/gdAccounting.jsp?status='+status+'&gd_id='+gd_id+'&gd_content_id='+gd_content_id+'&gd_name='+encodeURIComponent(gd_name)+'&gd_code='+gd_code+'&xm_name='+encodeURIComponent(xm_name)+'&xm_code='+xm_code,2000, 1000);
				return;
			}
			$.messager.confirm('确认','您确认要发起核算？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath%>/springMVC/gd/updateGDStatus",
						data:"gd_id="+gd_id+"&status=<%=com.beaut.project.util.StaticData.ACCOUTING%>",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
								openDialogResize('<%=contextPath%>/springViews/gd/gdAccounting.jsp?gd_id='
																	+ gd_id+'&gd_content_id='+gd_content_id
																	+ '&gd_name='
																	+ encodeURIComponent(gd_name)
																	+ '&gd_code='
																	+ gd_code
																	+ '&xm_name='
																	+ encodeURIComponent(xm_name)
																	+ '&xm_code='
																	+ xm_code,
															2000, 1000);
												} else {
													warningInfo(rtJson.rtMsrg);
												}
											}
										});
							}
						});
				}
			});
		}});
	}
		
		function doSearch2() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue2').val();
			jQuery('#gd_admin_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
	function doSearch() {
		var searchValue = $('#searchValue').val();
		var gd_status = $('#gd_status').combobox('getValue');
		var dept_id = $("#dept_id").combotree('getValue');
		var gd_admin_id = jQuery("#gd_admin_id").combotree('getValue');
		$('#table').datagrid('load', {
			searchValue : searchValue,
			dept_id : dept_id,
			gd_status : gd_status,
			gd_admin_id:gd_admin_id
		});
	}
</script>
<body style="height: 97%">
	<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
		<div style="float:left;">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" onclick="addGd();">新增</a>
		</div>
		<div align="right">
			派单人：<input type="text" id="gd_admin_id" name="gd_admin_id"   style="width:100px"> &nbsp;&nbsp;
			所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp;
			工单进度：<input id="gd_status" name="gd_status" />&nbsp;&nbsp; 
			工单编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="工单编号/名称" placeholder="工单编号/名称 "/>&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
	<div id="tba" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue2" name="searchValue2" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
</body>
</html>
